package com.iss.demo.controller;

import com.iss.demo.entity.Shopcar;
import com.iss.demo.model.MyResponseData;
import com.iss.demo.service.ShopcarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("shopcar/")
public class ShopcarController {
    @Autowired
    private ShopcarService service;

    @RequestMapping("selectAll")
    public List<Shopcar> selectAll(){
        List<Shopcar> list=service.selectAll();
        return list;
    }

    @RequestMapping("clear")
    public MyResponseData clear(){
        Integer a=service.clear();
        MyResponseData responseData = new MyResponseData();
        responseData.setErrorCode(0);
        responseData.setStatus("success");
        responseData.setObject("已清空购物车");
        return responseData;
    }

    @RequestMapping("selectById")
    public MyResponseData selectById(Integer id){
        Shopcar shopcar = service.selectById(id);
        MyResponseData responseData = new MyResponseData();
        responseData.setErrorCode(0);
        responseData.setStatus("success");
        responseData.setObject(shopcar);
        return responseData;
    }

    @RequestMapping("insert")
    public MyResponseData insert(Shopcar shopcar){
        Integer count = service.insert(shopcar);
        MyResponseData responseData = new MyResponseData();
        responseData.setErrorCode(0);
        responseData.setStatus("添加了"+count+"个网课到购物车");
        return responseData;
    }

    @RequestMapping("deleteOne")
    public MyResponseData delete(Integer s_id){
        Integer count = service.deleteOne(s_id);
        MyResponseData responseData = new MyResponseData();
        responseData.setErrorCode(0);
        responseData.setStatus("已删除商品");
        return responseData;
    }
}
